
//var rchannel = require("../utils/rchannel");
var userpush = require("../../../coinlib/coinpush");

module.exports = function(app) {
	return new ChatRemote(app);
};

var ChatRemote = function(app) {
	this.app = app;
	this.channelService = app.get('channelService');
};

/**
 * Add user into chat channel.
 *
 * @param {String} uid unique id for user
 * @param {String} sid server id
 * @param {String} name channel name
 * @param {boolean} flag channel parameter
 *
 */
ChatRemote.prototype.add = function(uid, sid, name, flag, cb) {
	var channel = this.channelService.getChannel(name, flag);

	if( !! channel) {
		channel.add(uid, sid);
		userpush.AddUser( sid)
	}
	cb();
};


/**
 * Kick user out chat channel.
 *
 * @param {String} uid unique id for user
 * @param {String} sid server id
 * @param {String} name channel name
 *
 */
ChatRemote.prototype.kick = function(uid, sid, name) {
	var channel = this.channelService.getChannel(name, false);
	// leave channel

	console.log("fuck we need kick " + uid + " " + sid)
	if( !! channel) {
		console.log("fuck2 we need kick " + uid + " " + sid)
		userpush.DelUser(uid)
		channel.leave(uid, sid);
	}
	/*
	var self = this;
	rchannel.UserLogout(uid, function(cname){
		channel = self.channelService.getChannel(cname, false);
		// leave channel
		if( !! channel) {
			channel.leave(uid, sid);
		}	
	});*/
};
